
data$forcing = as.integer(as.Date("1990-11-04"))- as.integer(as.Date(data$dob))
data$Cutoff08 = ifelse(data$forcing >= 0, 1, 0)






################# DV: Vote 2016 ########################

ivmod1_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                               downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)


ivmod1_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                             downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)
ivmod1_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                            downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2014 ##########################


ivmod2_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2012 ##########################

ivmod3_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2012_white", downstream_lag = "lag2012_white", bandwidth = 365, state.abbrev=NULL)

ivmod3_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "vote.gen2012_black", downstream_lag = "lag2012_black", bandwidth = 365, state.abbrev=NULL)
ivmod3_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "vote.gen2012_hispanic", downstream_lag = "lag2012_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Vote 2010 ##########################


ivmod4_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2010_white", downstream_lag = "lag2010_white", bandwidth = 365, state.abbrev=NULL)

ivmod4_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "vote.gen2010_black", downstream_lag = "lag2010_black", bandwidth = 365, state.abbrev=NULL)
ivmod4_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "vote.gen2010_hispanic", downstream_lag = "lag2010_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Democrat ##########################


ivmod5_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "democrat_white", downstream_lag = "lagdem_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "democrat_black", downstream_lag = "lagdem_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "democrat_hispanic", downstream_lag = "lagdem_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Republican ##########################


ivmod_rep_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "republican_white", downstream_lag = "lagrep_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "republican_black", downstream_lag = "lagrep_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "republican_hispanic", downstream_lag = "lagrep_hispanic", bandwidth = 365, state.abbrev=NULL)





##################### Registered ##########################


ivmod6_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "white", downstream_lag = "lagregistered_white", bandwidth = 365, state.abbrev=NULL)
ivmod6_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "black", downstream_lag = "lagregistered_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "hispanic", downstream_lag = "lagregistered_hispanic", bandwidth = 365, state.abbrev=NULL)




#################################################################################
######### Other cutoffs #########################################################
#################################################################################

data$forcing = as.integer(as.Date("1994-11-06"))- as.integer(as.Date(data$dob))

data$Cutoff12 = ifelse(data$forcing >=0, 1, 0)

################ 2012 Cutoff ####################
#vote 2016
ivmod1_white_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_white", 
                                            downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)
ivmod1_black_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_black", 
                                            downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)
ivmod1_hispanic_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_hispanic", 
                                               downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)




##################### DV: Vote 2014 ##########################


ivmod2_white_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_white", 
                                            downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_black", 
                                            downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_hispanic", 
                                              downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Democrat ##########################


ivmod5_white_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_white", 
                                            downstream_voted = "democrat_white", downstream_lag = "lagdem_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_black", 
                                            downstream_voted = "democrat_black", downstream_lag = "lagdem_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_hispanic", 
                                               downstream_voted = "democrat_hispanic", downstream_lag = "lagdem_hispanic", bandwidth = 365, state.abbrev=NULL)

##################### DV: Republican ##########################


ivmod_rep_white_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_white", 
                                               downstream_voted = "republican_white", downstream_lag = "lagrep_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_black", 
                                               downstream_voted = "republican_black", downstream_lag = "lagrep_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_hispanic", 
                                                  downstream_voted = "republican_hispanic", downstream_lag = "lagrep_hispanic", bandwidth = 365, state.abbrev=NULL)





##################### Registered ##########################


ivmod6_white_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_white", 
                                            downstream_voted = "white", downstream_lag = "lagregistered_white", bandwidth = 365, state.abbrev=NULL)

ivmod6_black_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_black", 
                                            downstream_voted = "black", downstream_lag = "lagregistered_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic_f12 = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff12", upstream_voted = "vote.gen2012_hispanic", 
                                               downstream_voted = "hispanic", downstream_lag = "lagregistered_hispanic", bandwidth = 365, state.abbrev=NULL)








rm(data)
filename = paste0("results_", state, ".Rdata")
save.image(paste0("results/", filename))
rm(list=ls(pattern = "mod"))
